package com.hr.dao;

import com.hr.model.Position;
import com.hr.model.Talent;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface TalentDAO
{
    @Results(id = "talent",value = {
            @Result(id = true, property = "id", column = "t_id"),
            @Result(property = "name", column = "t_name"),
            @Result(property = "level", column = "t_level"),
    })
    @Select("select * from talent where t_id=#{tid}")
    Talent getTalentByTId(@Param("tid")int tid);

    @ResultMap("talent")
    @Select("select * from talent where a_id=#{aid}")
    List<Talent> getTalentsByAId(@Param("aid")int aid);

    @SelectKey(keyProperty = "talent.id",before = false,resultType = Integer.class,statement = "select last_insert_id()")
    @Insert("insert into talent ( a_id, t_name, t_level) " +
            "values (#{aid},#{talent.name},#{talent.level})")
    void insertTalentByAId(@Param("aid")int aid,@Param("talent") Talent talent);

    @Update("update talent  " +
            "set t_name=#{talent.name},t_level=#{talent.level} where t_id=#{talent.id} and a_id=#{aid}")
    void updateTalent(@Param("aid")int aid, @Param("talent") Talent talent);

    @Update("delete from talent  where t_id=#{tid}")
    void deleteTalent(@Param("tid")int tid);
}
